KVM: MMU: always terminate page walks at level 1
authorLadi Prosek <lprosek@redhat.com>
Thu, 5 Oct 2017 09:10:23 +0000 (11:10 +0200)
committerSalvatore Bonaccorso <carnil@debian.org>
Sun, 15 Oct 2017 06:57:36 +0000 (07:57 +0100)
commit4d1684489d525754789fbfa05a40915dfe78a559
treeeda55f9737eb597b06852bb6f7b0d6d1f6d663dc
parent02b676074bdfd1505cee733efba654d42ec0ca33
KVM: MMU: always terminate page walks at level 1

is_last_gpte() is not equivalent to the pseudo-code given in commit
6bb69c9b69c31 ("KVM: MMU: simplify last_pte_bitmap") because an incorrect
value of last_nonleaf_level may override the result even if level == 1.

It is critical for is_last_gpte() to return true on level == 1 to
terminate page walks. Otherwise memory corruption may occur as level
is used as an index to various data structures throughout the page
walking code.  Even though the actual bug would be wherever the MMU is
initialized (as in the previous patch), be defensive and ensure here
that is_last_gpte() returns the correct value.

This patch is also enough to fix CVE-2017-12188.

Fixes: 6bb69c9b69c315200ddc2bc79aee14c0184cf5b2
Cc: stable@vger.kernel.org
Cc: Andy Honig <ahonig@google.com>
Signed-off-by: Ladi Prosek <lprosek@redhat.com>
[Panic if walk_addr_generic gets an incorrect level; this is a serious
 bug and it's not worth a WARN_ON where the recovery path might hide
 further exploitable issues; suggested by Andrew Honig. - Paolo]
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Gbp-Pq: Topic bugfix/x86
Gbp-Pq: Name KVM-MMU-always-terminate-page-walks-at-level-1.patch
arch/x86/kvm/mmu.c
arch/x86/kvm/paging_tmpl.h